<template>
  <el-dialog class="selfdlDialog_module" v-model="dialogVisible" :title="title">
    <slot></slot>
    <template #footer>
      <div class="selfdlDialog_footer">
        <el-button @click="closeDialog('cancel')">{{$t("btn_cancel")}}</el-button>
        <el-button type="primary" @click="closeDialog('ok')">{{$t("btn_ok")}}</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { defineComponent, defineExpose } from "vue";

export default defineComponent({
  props: {
    title: {
      type: String,
      required: false,
      default: "提示"
    },
    modelValue: {
      type: Boolean,
      default: true,
    },
    activeEvent: { // 确认后操作函数
        type: Function,
        required:true
    }
  },

  emits: ["update:modelValue"],
  setup(props,{emit}) {
       
    const closeDialog = (payload) => {
      if (payload === "ok") {
        props.activeEvent().then(() => {
          emit("update:modelValue", false);
        }).catch(() => {
         console.log("失败");
        })
      }else {
        emit("update:modelValue", false);
      }
    };
    defineExpose({
      dialogVisible: props.modelValue,
    });
    return {
      closeDialog,
      dialogVisible: props.modelValue,
    };
  },
});
</script>
<style scoped>


.selfdlDialog_footer {
    display: flex;
    justify-content: center;
    width: 100%;
}
</style>